//
//  ZYSplitViewController.m
//  commonProject
//
//  Created by 飞奔的羊 on 16/6/11.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "ZYSplitViewController.h"
#import "ZYMasterViewController.h"
#import "ZYDetailViewController.h"
@interface ZYSplitViewController ()
/**
 *  <#Description#>
 */
@property (nonatomic,strong)ZYMasterViewController *masterVc;
@end

@implementation ZYSplitViewController
- (instancetype)init
{
	if (self = [super init]) {
		//添加只控制器
		self.masterVc = [[ZYMasterViewController alloc]init];
		self.masterVc.view.backgroundColor = [UIColor redColor];
		[self addChildViewController:self.masterVc];
		[self.view addSubview:self.masterVc.view];
		
		ZYDetailViewController *detaiVC = [[ZYDetailViewController alloc]init];
		detaiVC.view.backgroundColor = [UIColor yellowColor];
		[self addChildViewController:detaiVC];
		[self.view addSubview:detaiVC.view];
		
	}
	return self;
}

//- (ZYMasterViewController *)masterVc
//{
//	if (!_masterVc) {
//		_masterVc = self.viewControllers[0];
//	}
//	return _masterVc;
//}
- (void)viewDidLoad {
    [super viewDidLoad];
    //设置展示 MasterVC 的展示方式
	/*
	 UISplitViewControllerDisplayModeAutomatic,  自动默认样式
	 UISplitViewControllerDisplayModePrimaryHidden, 主视图控制器隐藏,无论横竖屏都是.如果点击之后会有动画效果展示
	 UISplitViewControllerDisplayModeAllVisible,  主视图控制器全部显示,无论横竖屏
	 UISplitViewControllerDisplayModePrimaryOverlay,  主视图悬浮
	 */
	self.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
	//设置主视图的宽度(主视图的宽度)/(总得 soliteVC 的宽度)
	self.preferredPrimaryColumnWidthFraction = 0.5;
	
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChangeNotification) name:UIDeviceOrientationDidChangeNotification object:nil];
	

}
- (void)orientationDidChangeNotification
{
	BOOL portrait = UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation);
	//判断横竖屏
	if (portrait) {
		//竖屏
		self.maximumPrimaryColumnWidth = 60;
	}else {
		self.maximumPrimaryColumnWidth = 200;
	}
	[self.masterVc changePortraitUI:portrait];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//判断 sizeClasses 的 地方
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
{
//	ZYMasterViewController *masterVc = [[ZYMasterViewController alloc]init];
	BOOL portrait = self.traitCollection.verticalSizeClass == UIUserInterfaceSizeClassRegular && self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact;
	
//	if (self.traitCollection.verticalSizeClass == UIUserInterfaceSizeClassRegular && self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
//		//竖屏
//		[self.masterVc isShowContainerViews:NO];
//	} else {
	//横屏
		[self.masterVc isShowContainerViews:portrait];
//	}
	

}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
